package login

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetAuth(c *gin.Context) {
	userName := c.PostForm("username")
	password := c.PostForm("password")

	if userName != "andrew" || password != "andrew" {
		c.JSON(http.StatusUnauthorized, Response{
			Msg: "用户名或密码错误",
		})
		return
	}

	// 生成token
	token, err := GenerateToken(userName, password)
	if err != nil {
		c.JSON(http.StatusInternalServerError, Response{
			Msg: "生成token失败",
		})
		return
	}

	c.JSON(http.StatusOK, Response{
		Data: map[string]interface{}{
			"token": token,
		},
		Msg: "登录成功",
	})
}
